<!--
 * @Author: windys
 * @Description: 
 * @Date: 2022-02-14 15:52:30
-->
<template>
  <div class="article_page">
    <van-sticky>
      <!-- <van-nav-bar title="每日资讯">
        <template #right>
          <div class="nav_right" @click="handleHome">
            <van-icon name="manager" />
          </div>
        </template>
      </van-nav-bar> -->

      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item>
          <img
            src="http://vod.caihuapp.com/image/default/1070E86B24664EDE87823E8E8A630C43-6-2.jpeg"
            alt=""
            srcset=""
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="http://vod.caihuapp.com/image/default/F43C5758FF6543DF9C0BA52DCA7A8DC5-6-2.jpg"
            alt=""
            srcset=""
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="http://vod.caihuapp.com/image/default/71FF1E8B4864481DBFACAAC726FBCEBC-6-2.jpg"
            alt=""
            srcset=""
          />
        </van-swipe-item>
        <van-swipe-item>
          <img
            src="http://vod.caihuapp.com/image/default/0708DC17001B443DAC3A2E3D1522E992-6-2.jpg"
            alt=""
            srcset=""
          />
        </van-swipe-item>
      </van-swipe>

      <div class="tab">
        <van-tag
          type="primary"
          size="large"
          style="margin: 0 0px"
          :plain="query.marketId != ''"
          @click="handleChaneType('')"
          >推荐</van-tag
        >
        <van-tag
          type="primary"
          size="large"
          style="margin: 0 20px"
          :plain="query.marketId != '011'"
          @click="handleChaneType('011')"
          >财经</van-tag
        >
      </div>
    </van-sticky>

    <div class="list">
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          class="list_item"
          v-for="(item, index) in list"
          :key="index"
          @click="handleClick(item)"
        >
          <div class="item_img">
            <van-image
              width="100"
              height="80"
              :src="item.titleUrl"
              alt=""
              srcset=""
            />
          </div>
          <div class="item_right">
            <p class="item_title">
              {{ item.articleTitle }}
            </p>
            <p class="item_time">{{ item.publishTime }}</p>
            <p class="item_small_title">
              {{ item.abstracts }}
            </p>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>



<script >
import { defineComponent, onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { getArticleList } from "../../api/article";
export default defineComponent({
  setup() {
    const router = useRouter();
    const handleHome = () => {
      router.push("/my");
    };

    const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);

    const query = reactive({
      pageIndex: 0,
      pageSize: 10,
      marketId: "",
      ruleState: 1, //	1-全部，2-免费，3-收费，4-会员免费
    });

    // 加载
    const onLoad = async () => {
      query.pageIndex++;
      const res = await getArticleList(query);
      if (res) {
        list.value = list.value.concat(res);
        loading.value = false;
        if (res.length <= 0) {
          console.log(111111);
          finished.value = true;
        } else {
          finished.value = false;
        }
      }
    };

    const handleChaneType = (v) => {
      query.marketId = v;
      query.pageIndex = 0;
      list.value = [];
      onLoad();
    };

    const handleClick = (item) => {
      router.push({
        path: "/articledetail",
        query: {
          articleId: item.articleId,
        },
      });
    };
    return {
      loading,
      finished,
      query,
      list,
      onLoad,
      handleHome,
      handleClick,
      handleChaneType,
    };
  },
});
</script>


<style lang="scss" scoped>
.article_page {
  .nav_right {
    color: #fff;
    display: flex;
    span {
      line-height: 50px;
      margin-right: 5px;
    }
  }
  .tab {
    background: #fff;
    text-align: left;
    height: 40px;
    line-height: 40px;
    padding: 0 10px;
  }
  .list {
    display: flex;
    flex-direction: column;
    padding: 10px 10px;
    .list_item {
      height: 100px;
      display: flex;
      flex-direction: row;
      margin-bottom: 10px;
      .item_img {
        width: 120px;
        height: 100px;
        overflow: hidden;
        padding-top: 15px;
      }
      .item_right {
        width: calc(100% - 120px);
        font-size: 12px;
        text-align: left;
        padding-left: 10px;
        .item_title {
          font-size: 14px;
          font-weight: 400;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .item_time {
          margin-top: 14px;
        }
        .item_small_title {
          color: #9e9595;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}


.my-swipe .van-swipe-item {
  overflow: hidden;
  height: 200px;
  img {
    width: 100%;
    height: 100%;
  }
}


.van-swipe{
  overflow: hidden;
  width: 95%;
  margin: 10px auto;
  border-radius: 8px;
  box-shadow: 0 12px 10px rgba(80, 79, 79, 0.247);
}
::v-deep(.van-sticky--fixed){
  background: #ffffff;
}
</style>